package cn.com.wdjedu.androidapp.wjeduandroid.ui.videoshow.adpter;

import android.content.Context;
import android.view.View;

import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.List;

import cn.com.wdjedu.androidapp.wjeduandroid.R;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.video.videoBean;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.Constanct;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.videoshow.VideoShowActivity;

/**
 * 章节子图示的适配器
 */

public class SubChapterFragmentAdapter extends  CommonAdapter<videoBean.DataBean.ListsBean> {

    private String chapterNum;
    private String[] chapter;
    private String[] SubChapter;
    private Boolean color;
    private VideoShowActivity activity;

    public SubChapterFragmentAdapter(Context context, int layoutId, List<videoBean.DataBean.ListsBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(final ViewHolder viewHolder, final videoBean.DataBean.ListsBean item, final int position) {
        chapter= item.getVideo_path().split("-");
        chapterNum=chapter[2]+"-"+chapter[3];
        SubChapter=chapterNum.split("\\.");
        viewHolder.setText(R.id.chapter_num,SubChapter[0]);
        viewHolder.setText(R.id.chapter_name,item.getName());
        viewHolder.setText(R.id.chapter_time,item.getVideo_time());
        activity = (VideoShowActivity) mContext;
        if(activity.getPosition() == position){
            viewHolder.setTextColor(R.id.chapter_num,mContext.getResources().getColor(R.color.txtselect));
            viewHolder.setTextColor(R.id.chapter_name,mContext.getResources().getColor(R.color.txtselect));
            viewHolder.setTextColor(R.id.chapter_time,mContext.getResources().getColor(R.color.txtselect));
        }else {
            viewHolder.setTextColor(R.id.chapter_num,mContext.getResources().getColor(R.color.black));
            viewHolder.setTextColor(R.id.chapter_name,mContext.getResources().getColor(R.color.black));
            viewHolder.setTextColor(R.id.chapter_time,mContext.getResources().getColor(R.color.black));
        }
        viewHolder.setOnClickListener(R.id.chapter_item, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Constanct.PLAYING_URL=item.getVideo_path();
                Constanct.PLAYING_NAME=item.getName();
                activity.setPosition(position);
                activity.playVideo();
                notifyDataSetChanged();

//                Intent intent = new Intent(activity.getApplication(), VideoShowActivity.class);
//                intent.putExtra("videopath",item.getVideo_path());
//                intent.putExtra("videoUnit",String.valueOf(item.getUnit()));
//                intent.putExtra("videoName",item.getName());
              //Toast.makeText(mContext,"章节内点击视频"+ Constanct.PLAYING_URL,Toast.LENGTH_LONG).show();
              //   activity.finish();
              //  activity.startActivityForResult(intent,1);
            }
        });

    }



}
